console.log("=============background")
// 监听发送请求
chrome.webRequest.onBeforeRequest.addListener(function(details) {
    console.log(details)
    if (details.url.indexOf('jquery-1.7.1.min.js') > -1) {
      return {redirectUrl: 'https://cdn.bootcss.com/jquery/1.7.1/jquery.min.js'};
    }
    if (details.url.indexOf('form.min.js') > -1) {
      return {redirectUrl: 'https://cdn.bootcss.com/jquery.form/4.2.1/jquery.form.min.js'};
    }
    if (details.url.indexOf('cookie.js') > -1) {
      return {redirectUrl: 'https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js'};
    }


    if (details.url.indexOf('swfupload/swfupload.js') > -1) {
      return {redirectUrl: 'http://lanyue.oschina.io/insert/js/swfupload.js'};
    }
    if (details.url.indexOf('swfupload/swfupload.cn.js') > -1) {
      return {redirectUrl: chrome.extension.getURL('/js/swfupload.cn.js')};
    }
    if (details.url.indexOf('swfupload/handlers.js') > -1) {
      return {redirectUrl: chrome.extension.getURL('js/handlers.js')};
    }
    // 可能安全性问题，swf不能本地加载
    /*if (details.url.indexOf('swfupload/swfupload.swf') > -1) {
      return {redirectUrl: chrome.extension.getURL('js/swfupload.swf')};
    }*/
    if (details.url.indexOf('swfupload/swfupload.swf') > -1) {
      return {redirectUrl: 'http://lanyue.oschina.io/insert/js/swfupload.swf'};
    }
    /*if (details.url.indexOf('swfupload/swfupload.js') > -1) {
      return {redirectUrl: 'http://lanyue.oschina.io/insert/js/swfupload.js'};
    }
    if (details.url.indexOf('swfupload/swfupload.cn.js') > -1) {
      return {redirectUrl: 'http://lanyue.oschina.io/insert/js/swfupload.cn.js'};
    }
    if (details.url.indexOf('swfupload/handlers.js') > -1) {
      return {redirectUrl: 'http://lanyue.oschina.io/insert/js/handlers.js'};
    }
    if (details.url.indexOf('swfupload/swfupload.swf') > -1) {
      return {redirectUrl: 'http://lanyue.oschina.io/insert/js/swfupload.swf'};
    }*/
    console.log("没有匹配到", details.url)
    return {cancel: details.url.indexOf("172.16.0.156:8080") != -1};
  },
  {
    //配置拦截匹配的url，数组里域名下的资源都将被拦截
    urls: [
        // "*://*/script/jquery/*",
        // "*://*/script/swfupload/*",
        "http://172.16.0.156:8080/script/jquery/*",
        "http://172.16.0.156:8080/script/swfupload/*"
        // "*://*.elongstatic.com/*"
    ],
    //拦截的资源类型，在这里只拦截script脚本，也可以拦截image等其他静态资源
    //main_frame, sub_frame, stylesheet, script, image, font, object, xmlhttprequest, ping, other
    types: ["script", "other", "object"]
  },
  //要执行的操作，这里配置为阻断
  ["blocking"]
);
